package com.zhuss.order.processor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.order.order.SearchPrepayBo;
import com.zhuss.bean.vo.order.order.ListPrepayVo;
import com.zhuss.common.PageVo;
import com.zhuss.exception.DzcxException;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.order.db.dao.ext.PrepayDao;
import com.zhuss.order.db.entity.Prepay;


/**
 * @description: 预支付读
 * @author: zhushanshuo
 * @create: Tue Jan 12 18:10:03 CST 2021
 **/
@Component("prepayRead")
public class PrepayRead {
	
	@Autowired
	private PrepayDao prepayDao;
	
	
	/**
	 * 预支付
	 * @return
	 */
	public Object listPrepay(List<Long> prepayIdList) {
		List<Prepay> result = prepayDao.listById(prepayIdList);
		return result;
	}
	
	
	/**
	 * 根据名字查询预支付
	 * @param 
	 * @return
	 */
	public List<Prepay> list(String name) {
		List<Prepay> result = prepayDao.listByName(name);
		return result;
	}
	
	public List<Prepay> listNotId(String name, Long prepayId) {
		List<Prepay> result = new ArrayList<Prepay>();
		List<Prepay> list = list(name);
		for (Prepay c : list) {
			if (!c.getPrepayId().equals(prepayId)) {
				result.add(c);
				break;
			}
		}
		return result;
	}
	
	/**
	 * 预支付 
	 * @return
	 */
	public Object listPrepayId() {
		List<Prepay> prepayList = prepayDao.listAll();
		List<Long> result = new ArrayList<>();
		transferListId(prepayList, result);
		return result;
	}
	
	private void transferListId(List<Prepay> prepayList, List<Long> result) {
		for (Prepay item : prepayList) {
			result.add(item.getPrepayId());
		}
	}

	/**
	 * 预支付列表
	 * @param bo
	 * @return
	 */
	public Object list(SearchPrepayBo bo) {
		PageVo<ListPrepayVo> result = new PageVo<ListPrepayVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(prepayDao.list(bo));
        result.setTotal(prepayDao.countList(bo));
		return result;
	}
	
	/**
	 * 预支付详情
	 * @param prepayId
	 * @return
	 * @throws DzcxException
	 */
	public Object detail(Long prepayId) throws DzcxException {
		Object result = prepayDao.detail(prepayId);
		if (result == null) {
			throw new DzcxException(ExceptionCode.数据不存在);
		}
		return result;
	}
	
	

}
